using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SilkSharp
{
	/*
	 * Convert input to a log scale
	 *  
	 * @author Jing Dai
	 * @author Dingxin Xu
	 */
	public class Silk_lin2log
	{
		/*
		 * Approximation of 128 * log2() (very close inverse of approx 2^() below) 
		 * Convert input to a log scale.
		 * 
		 * @param inLin Input in linear scale
		 * @return
		 */
		// JAVA DEVELOPERS!! Y U NO MAKE EVERYTHING PUBLIC!
		public static int SKP_Silk_lin2log( int inLin )    /* I:    Input in linear scale */
		{
			int lz, frac_Q7;

			int[] lz_ptr = new int[1];
			int[] frac_Q7_ptr = new int[1];
	    
			Silk_Inlines.SKP_Silk_CLZ_FRAC( inLin, lz_ptr, frac_Q7_ptr );
			lz = lz_ptr[0];
			frac_Q7 = frac_Q7_ptr[0];
	    
			/* Piece-wise parabolic approximation */
			return( Silk_SigProc_FIX.SKP_LSHIFT( 31 - lz, 7 ) + Silk_macros.SKP_SMLAWB( frac_Q7, Silk_SigProc_FIX.SKP_MUL( frac_Q7, 128 - frac_Q7 ), 179 ) );
		}
	}
}
